<script>
    $(document).ready(function(){
        $('.easyui-validatebox').bind('blur',function(){
            var val = $(this).val();
            var error_id = $(this).attr('name')+'_error_span';
            var tip_id = $(this).attr('name')+'_tip_span';
            $('#'+tip_id).hide();
            switch ($(this).attr('name'))
            {
                case 'name': {
                    if (val == '' || val == null)
                    {
                        $('#'+error_id).show();
                    }
                    else
                    {
                        $('#'+error_id).hide();
                    }
                    break;
                };
                case 'email': {
                    if (!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,4}){1,2})$/.test(val)))
                    {
                        $('#'+error_id+'_i').show();
                        return;
                    }
                     $.ajax({
                        type: "POST",
                        url: "?r=site/checkEmail",
                        data: "email="+val,
                        success: function(msg){
                            if (msg == 'true')
                            {
                                $('#'+error_id+'_i').hide();
                                $('#'+error_id).hide();
                            }
                            else
                            {
                                $('#'+error_id+'_i').hide();
                                $('#'+error_id).show();
                                
                            }
                        }

                    });
                }
                case 'password': {
                    if (val.length<6)
                    {
                        $('#'+error_id).show();
                    }
                    else
                    {
                        $('#'+error_id).hide();
                    }
                    break;
                }
                case 'password_agin': {
                    if (val != $("input[name='password']").val())
                    {
                        $('#'+error_id).show();
                    }
                    else
                    {
                        $('#'+error_id).hide();
                    }
                    break;
                }
                case 'school': {
                    if (val == '' || val ==null)
                    {
                        $('#'+error_id).show();
                    }
                    else
                    {
                        $('#'+error_id).hide();
                    }
                    break;
                }                
                case 'captcha': {
                    if (val == '' || val ==null)
                    {
                        $('#'+error_id).show();
                    }
                    else
                    {
                        $.ajax({
                            type: "POST",
                            url: "?r=site/checkCaptcha",
                            data: "captcha="+val,
                            success: function(msg){
                                if (msg == 'true')
                                {
                                    $('#'+error_id).hide();
                                }
                                else
                                {
                                   $('#'+error_id).show();
                                    
                                }
                            }
                        })
                    }
                    break;
                }
                default:break;
            }
            
        
        })
        $('.easyui-validatebox').bind('focus',function(){
            $('#last_erro_span').hide(); 
            var error_id = $(this).attr('name')+'_error_span';
            var tip_id = $(this).attr('name')+'_tip_span';
            $('#' + error_id).hide();
            $('#' + tip_id).show();

        })
        $("form").submit(function () {
            if ($(".box-error").hide().length < 7 || $('.easyui-validatebox').val() =='')
            {
                $('#last_erro_span').show(); 
                return false;
            }
            else
            {
               return true;
            }
        });
    
    })
</script>
	<div class="demo-info">
		<div class="demo-tip icon-tip"></div>
		<div>免费开通天校网帐号</div>
	</div>
<div style="background:#fafafa;padding:10px;width:350px;height:300px;">
    <form id="ff" method="post" novalidate action= '?r=site/regist'>
        <div>
            <label for="name">真实姓名:</label>
            <input class="easyui-validatebox" type="text" name="name"></input><span id="xmg"></span><span id="name_error_span" style = 'display:none' class="box-error">名字不能为空</span><span id="name_tip_span" style = 'display:none' class="box-error">请输入你的名字</span>
        </div>
        <div>
            <label for="email">邮箱:</label>
            <input class="easyui-validatebox" type="text" name="email"></input><span  id="dmmg"></span><span  id="email_error_span" class="box-error" style = "display:none">已被注册不可用</span><span  id="email_error_span_i" class="box-error" style = "display:none">请输入正确的邮箱</span>
        </div>
        <div>
            <label for="password">密码:</label>
            <input class="easyui-validatebox" type="password"  name="password"></input><span id="mmg"></span><span id="password_error_span" class="box-error" style = "display:none">密码长度不能少于6</span>
        </div>
        <div>
            <label for="password_agin">确认密码:</label>
            <input class="easyui-validatebox" type="password" name="password_agin"></input><span id="password_agin_error_span" class="box-error" style = "display:none">两次密码不一致</span>
        </div>
        <div>
            <label for="school">学校:</label>
            <input class="easyui-validatebox" type="text" name="school"></input><span id='school_error_span' style = "display:none" class="box-error">学校不能为空</span>
        </div>
        <div>
            <label for="captcha">验证码:</label>
            <input class="easyui-validatebox" type="text" name="captcha"></input><span id='captcha_error_span' style = "display:none" class="box-error">请输入正确的验证码</span><br/>
            <?php $this->widget('CCaptcha',array('clickableImage' => true,'showRefreshButton' => false,'imageOptions' => array ('alt' => '验证码', 'title' => '看不清，换一张', 'style' => 'vertical-align:middle;cursor:pointer;height:26px;width:70px;border:1px #dadada solid;margin-left:5px;' ))); ?>
        </div>
        <div>
            <input type="submit" value="现在注册"><span id='last_erro_span' style='display:none'>请检查各项数据</span>
        </div>
    </form>
</div>

